package net.hands.common.mail;

import java.util.Properties;

import javax.mail.Authenticator;
/**
 * 
 *说明:smtp加密服务
 * <br>
 * <p>这是一个开源的软件，请在LGPLv3下合法使用、修改或重新发布。</p>
 * @author 陈侃(cknet@126.com, 13910090885)
 *         http://code.google.com/p/simpleframework/
 *         http://www.simpleframework.net
 */
public class SmtpSslServer extends SmtpServer {
	/**
	 * 
	 */
	protected static final String MAIL_SMTP_STARTTLS_ENABLE = "mail.smtp.starttls.enable";
	/**
	 * smtp加密端口
	 */
	protected static final String MAIL_SMTP_SOCKET_FACTORY_PORT = "mail.smtp.socketFactory.port";
	/**
	 * smtp加密类
	 */
	protected static final String MAIL_SMTP_SOCKET_FACTORY_CLASS = "mail.smtp.socketFactory.class";
	/**
	 * smtp加密回退
	 */
	protected static final String MAIL_SMTP_SOCKET_FACTORY_FALLBACK = "mail.smtp.socketFactory.fallback";
	/**
	 * 默认端口
	 */
	protected static final int DEFAULT_SSL_PORT = 465;
	/**
	 * 
	 * Constructor Method  
	 * @update 2012-9-21 下午2:59:23  
	 * @param host 主机
	 * @param authenticator 认证
	 */
	public SmtpSslServer(final String host, final Authenticator authenticator) {
		super(host, DEFAULT_SSL_PORT, authenticator);
	}
	/**
	 * 
	 * Constructor Method  
	 * @update 2012-9-21 下午2:59:27  
	 * @param host 主机
	 * @param username 用户名
	 * @param password 密码
	 */
	public SmtpSslServer(final String host, final String username, final String password) {
		super(host, DEFAULT_SSL_PORT, username, password);
	}
   /**
    * 
   * Constructor Method  
   * @update 2012-9-21 下午2:59:35  
   * @param host 主机
   * @param port 端口
   * @param authenticator 认证
    */
	public SmtpSslServer(final String host, final int port, final Authenticator authenticator) {
		super(host, port, authenticator);
	}
   /**
    * 
   * Constructor Method  
   * @update 2012-9-21 下午2:59:39  
   * @param host 主机
   * @param port 端口
   * @param username 用户名
   * @param password 密码
    */
	public SmtpSslServer(final String host, final int port, final String username,
			final String password) {
		super(host, port, username, password);
	}
   /**
    * 
   (non-Javadoc)  
   * @see net.hands.common.mail.SmtpServer#createSessionProperties()  
   * @update 2012-9-21 下午3:09:22
    */
	@Override
	protected Properties createSessionProperties() {
		final Properties props = super.createSessionProperties();
		props.setProperty(MAIL_SMTP_STARTTLS_ENABLE, "true");
		props.setProperty(MAIL_SMTP_SOCKET_FACTORY_PORT, String.valueOf(port));
		props.setProperty(MAIL_SMTP_PORT, String.valueOf(port));
		props.setProperty(MAIL_SMTP_SOCKET_FACTORY_CLASS, "javax.net.ssl.SSLSocketFactory");
		props.setProperty(MAIL_SMTP_SOCKET_FACTORY_FALLBACK, "false");
		props.setProperty(MAIL_HOST, host);
		return props;
	}
}